package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseAuditApi;
import com.xuecheng.api.content.model.dto.CourseBaseDTO;
import com.xuecheng.api.content.model.qo.QueryCourseModel;
import com.xuecheng.api.content.model.vo.CourseAuditVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.content.convert.CourseBaseConvert;
import com.xuecheng.content.service.CourseBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
public class CourseAuditController implements CourseAuditApi {

    // 运营平台标识--可以查询所有教学机构的数据
    public static final Long OPERATION_FLAG = -99887799L;
    @Autowired
    private CourseBaseService courseBaseService;


    /**
     * 课程信息查询实现-运营
     *
     * @param params           分页封装类
     * @param queryCourseModel 请求体
     * @return 分页查询结果
     */
    @PostMapping("m/course/list")
    public PageVO queryCourseList(PageRequestParams params,
                                  @RequestBody QueryCourseModel queryCourseModel) {

        //调用service分页查询,PageVO接收
        PageVO<CourseBaseDTO> pageVO = courseBaseService.queryCourseList(params, queryCourseModel, OPERATION_FLAG);
        return pageVO;
    }

    /**
     * 课程信息审核实现-运营
     *
     * @param courseAuditVO 课程审核时的VO对象
     */
    @PostMapping("m/courseReview/approve")
    public void approveCourse(@RequestBody CourseAuditVO courseAuditVO) {

        CourseBaseDTO courseBaseDTO = CourseBaseConvert.INSTANCE.vo2auditDto(courseAuditVO);
        //审核
        courseBaseService.approve(courseBaseDTO);
    }

}
